
// 第三题 练习1
const fp = require('lodash/fp')
const {Maybe, Container} = require('./support')

let maybe = Maybe.of([5,6,1])

let ex1 = (options) => {
  return fp.map(fp.add(1), options)
}
console.log(maybe.map(ex1)._value)

// 练习2
let xs = Container.of(['do', 'ray', 'me', 'fa', 'so', 'la', 'ti', 'do'])
let ex2 = (options) => {
  return fp.first(options)
}
console.log(xs.map(ex2)._value)

//练习3
let safeProp = fp.curry(function(x, o){
  return Maybe.of(o[x])
})
let user = { id: 2, name: 'Albert' }
let firstChart = Container.of(user)
let ex3 = (options) => {
  const getName = safeProp('name')
  return getName(options).map(fp.first)._value
}
console.log(firstChart.map(ex3)._value)


const pi = Maybe.of(1)
const piNull = Maybe.of(null)
let ex4 = function(n){
  return parseInt(n)
}
console.log(pi.map(ex4)._value)
console.log(piNull.map(ex4)._value)